#include "stdinc.h"

#pragma unmanaged

void CallHook::initialize(DWORD place, void* hookToInstall)
{
	pPlace = (PBYTE)place;
	memcpy(bOriginalCode, pPlace, sizeof(bOriginalCode));
	pOriginal = pPlace + sizeof(bOriginalCode) + *(ptrdiff_t*) (bOriginalCode + 1);
	hook = hookToInstall;
}
void CallHook::installHook(void *hookToInstall)
{
	if(hookToInstall) hook = hookToInstall;
	if(hook) {
		*(ptrdiff_t*) (pPlace + 1) = (PBYTE) hook - pPlace - 5;
	}
}
void CallHook::releaseHook()
{
	memcpy(pPlace + 1, bOriginalCode + 1, sizeof(bOriginalCode) - 1);
}